package com.waghost.bridalgown.controller;

import com.waghost.bridalgown.annotaion.Logging;
import com.waghost.bridalgown.entity.Result;
import com.waghost.bridalgown.entity.Works;
import com.waghost.bridalgown.entity.UserInfo;
import com.waghost.bridalgown.service.WorksService;
import com.waghost.bridalgown.utils.UserUtils;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
// 甄选作品
@RestController
@CrossOrigin
@AllArgsConstructor
@RequestMapping("/works")
public class WorksController {

    private WorksService worksService;
    private UserUtils utils;
    @GetMapping("/list")
    public Result list() {
        return worksService.list();
    }
    @GetMapping("/get/{id}")
    public Result get(@PathVariable("id") Integer id) {
        return worksService.getId(id);
    }
    @GetMapping("/getUser")
    public Result getUser(HttpServletRequest request) {
        UserInfo user = utils.getUser(request);
        return worksService.getUserId(user.getId());
    }

    @PostMapping("/add")
    @Logging(type = 1,uuid = 4)
    public Result addUser(@RequestBody Works works,HttpServletRequest request) {
        works.setCreateUser(utils.getUser(request).getId());
        return worksService.add(works);
    }

    @PostMapping("/edit")
    @Logging(type = 3,uuid = 4)
    public Result editUser(@RequestBody Works works) {
        return worksService.update(works);
    }

    @PostMapping("/del/{id}")
    @Logging(type = 2,uuid = 4)
    public Result delUser(@PathVariable("id") Integer id) {
        return worksService.delete(id);
    }


}
